//
//  IndexServiceView.m
//  YunFu
//
//  Created by Bager on 2018/8/30.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "IndexServiceView.h"

#import "IndexFourItemSizeCell.h"

@implementation IndexServiceView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = HexColor(0xf4f5f6);
        [self createView];
        [self createTitleView];
    }
    return self;
}

- (void)createTitleView
{
    UILabel *labelDown = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 45, 5, 90, 30)];
    labelDown.textAlignment = NSTextAlignmentCenter;
    labelDown.text = @"便民服务";
    labelDown.font = [UIFont systemFontOfSize:14];
    labelDown.backgroundColor = HexColor(0x48e89e);
    labelDown.layer.cornerRadius = 14;
    labelDown.layer.masksToBounds = YES;
    labelDown.adjustsFontSizeToFitWidth = YES;
    labelDown.textColor = [UIColor whiteColor];
    [self addSubview:labelDown];
}

- (void)createView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置每个item的大小，
    flowLayout.itemSize = CGSizeMake((kScreenWidth - kPublicMargin * 2) / 4.0, 70);
    // 设置列的最小间距
    flowLayout.minimumInteritemSpacing = 0;
    // 设置最小行间距
    flowLayout.minimumLineSpacing = 0;
    // 设置布局的内边距
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
    // 滚动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.serviceCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kPublicMargin, 20, kScreenWidth - kPublicMargin * 2, 70 * 2 + 20)  collectionViewLayout:flowLayout];
    
    self.serviceCollectionView.backgroundColor = [UIColor whiteColor];
    
    self.serviceCollectionView.dataSource = self;
    
    self.serviceCollectionView.delegate = self;
    
    [self.serviceCollectionView registerClass:[IndexFourItemSizeCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
    
    self.serviceCollectionView.layer.cornerRadius = 4;
    self.serviceCollectionView.layer.masksToBounds = YES;
    
    [self addSubview:self.serviceCollectionView];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    IndexFourItemSizeCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    
    NSArray *imgArray = @[@"yf1-fldh1",@"yf1-fldh2",@"yf1-fldh3",@"yf1-fldh4",@"yf1-fldh5",@"yf1-fldh6",@"yf1-fldh7",@"yf1-fldh8"];
    [cell.img setImage:[UIImage imageNamed:imgArray[indexPath.item]]];
    NSArray *titleArray = @[@"生活缴费", @"家政服务", @"火/客车票", @"景点门票", @"招聘", @"房屋", @"公车辆", @"二手"];
    cell.name.text = titleArray[indexPath.item];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}


@end
